'use strict';
app.controller('chainEditCtrl',['$scope','utilService','chainEditService','toaster','$state',function($scope,utilService,chainEditService,toaster,$state){
    $scope.chain={};

    //查找品牌信息
    $scope.query=function(){
        utilService.get({
            url:$scope.app.domain+'chain/session'
        }).then(
            function(res){
                $scope.chain=res.data.data;
            }
        );
    }
    $scope.query();

    //查找行业下拉框列表
    $scope.queryIndustrySel=function(){
        utilService.get({
            url:$scope.app.domain+'industry/get/all'
        }).then(
            function(rlt){
                $scope.industrySel=rlt.data.data;
            }
        );
    }
    $scope.queryIndustrySel();

    //查找套餐下拉框列表
    $scope.querySetMealSel=function(){
        utilService.get({
            url:$scope.app.domain+"set/meal/list/name"
        }).then(
            function(rlt){
                $scope.setMealSel=rlt.data.data;
            }
        );
    }
    $scope.querySetMealSel();

    //保存店铺基本信息
    $scope.updateState=false;
    $scope.updateChain=function(){
        if($scope.updateState){
            return;
        }
        $scope.updateState=true;
        chainEditService.updateChain($scope).then(
            function(rlt){
                switch(rlt.status) {
                    case 200:
                        toaster.pop('success',"提示","操作成功");
                        $scope.updateState=false;
                        $state.go('app.chainDatum');
                        break;
                    default:
                        toaster.pop('error',"操作失败","发生未知错误!请联系管理员");
                        $scope.updateState=false;
                        break;
                }
            }
        );
    }
}]);